﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Pavilion.DesignerTool
{
    static public class GameItemWrapperManager 
    {
        static public IEnumerable<GameItemWrapper> GameItemWrapperCollection { get { return gameItemWrapperCollection; } }

        static private NotifiableCollection<GameItemWrapper> gameItemWrapperCollection = new NotifiableCollection<GameItemWrapper>();
        static private GameController gameController = new GameController();

        static GameItemWrapperManager()
        {
            gameItemWrapperCollection.Add(new GameItemWrapper(null));
        }

        static public void RemoveGameItemWrapper(GameItemWrapper gameItemWrapper)
        {
            gameItemWrapperCollection.Remove(gameItemWrapper);
        }

        static public GameItemWrapper GetGameItemWrapper(string name)
        {
            if (string.IsNullOrEmpty(name))
                return gameItemWrapperCollection.Last();

            GameItemWrapper gameItemWrapper = GameItemWrapperCollection.FirstOrDefault((x) => x.GameItem != null && x.GameItem.Name == name);

            if (gameItemWrapper == null)
            {
                gameItemWrapper = new GameItemWrapper(name);
                gameItemWrapperCollection.Insert(gameItemWrapperCollection.Count - 1, gameItemWrapper);
            }
            
            return gameItemWrapper;
        }
    }
}
